package net.atomarrow.controllers.converter;

import net.atomarrow.util.StringUtil;

public class BooleanConverter implements IConverter {

    @Override
    public boolean canHandle(Class clazz) {
        return clazz == Boolean.class || clazz == Boolean.TYPE;
    }

    @Override
    public <T> T converter(Object[] values, Class<T> clazz) throws Exception{
        Object value =values[0];
        if(value==null||StringUtil.isBlank(value.toString())){
            if(clazz==Boolean.TYPE){
                return (T) new Boolean(false);
            }
            return null;
        }
        return (T) new Boolean(value.toString());
    }
}
